#pragma once

#include "StructuralFeatureAction.h"

#include "InputPin.h"
#include "StructuralFeature.h"

namespace uml {

StructuralFeatureAction::StructuralFeatureAction(const QString& umlType)
    : Action(umlType) {}

void StructuralFeatureAction::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    Action::fromJson(json, errorList);
    object_ = JsonSerializable::create<InputPin>(json.value("object"), errorList);

    structuralFeature_ = JsonSerializable::create<StructuralFeature>(json.value("structuralFeature"), errorList);

}

void StructuralFeatureAction::toJson(QJsonObject& json) {
    Action::toJson(json);
    if (object_) {
        QJsonObject object_json;
        object_->toJson(object_json);
        json.insert("object", object_json);
    }
    if (structuralFeature_) {
        QJsonObject structuralFeature_json;
        structuralFeature_->toJson(structuralFeature_json);
        json.insert("structuralFeature", structuralFeature_json);
    }
}

/// <summary>
/// object getter
/// The InputPin from which the object whose StructuralFeature is to be read or
/// written is obtained.
/// </summary>
shared_ptr<InputPin> StructuralFeatureAction::object() const {
    return object_;
}

/// <summary>
/// object setter
/// The InputPin from which the object whose StructuralFeature is to be read or
/// written is obtained.
/// </summary>
void StructuralFeatureAction::setObject(shared_ptr<InputPin> value) {
    object_ = value;
}

/// <summary>
/// structuralFeature getter
/// The StructuralFeature to be read or written.
/// </summary>
shared_ptr<StructuralFeature> StructuralFeatureAction::structuralFeature() const {
    return structuralFeature_;
}

/// <summary>
/// structuralFeature setter
/// The StructuralFeature to be read or written.
/// </summary>
void StructuralFeatureAction::setStructuralFeature(shared_ptr<StructuralFeature> value) {
    structuralFeature_ = value;
}

} // namespace uml
